home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_9.zip / DBX.C < prev    next >
C/C++ Source or Header  |  1993-07-27  |  44KB  |  1,797 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. /* interface to dbx for sem debugging */
  10. /* interface to dbx for sem debugging */
  11. #include "hdr.h"
  12. #include "libhdr.h"
  13. #include "vars.h"
  14. #include "ifile.h"
  15. #include "setp.h"
  16. #include "arithp.h"
  17. #include "sspansp.h"
  18. #include "chapp.h"
  19. #include "librp.h"
  20. #include "miscp.h"
  21. #include "smiscp.h"
  22. #include "dbxp.h"
  23.  
  24. #ifndef EXPORT
  25.  
  26. typedef struct explored
  27. {
  28.     short genre;    /* discriminant : is explored a node or a symbol ? */
  29.  
  30.     union {
  31.         Node   n;
  32.         Symbol s;
  33.     } addr;
  34. } explored;
  35.  
  36. #define UNDEFINED_STEP 99
  37. #define EXIT_STEP 100
  38. #define NODE_GENRE 0
  39. #define SYMBOL_GENRE 1
  40.  
  41.  
  42.  
  43. int zpadr_opt = 1;
  44. Symbol zsym;
  45. Set    zset;
  46. Node    znod;
  47. Declaredmap    zdcl;
  48. Tuple ztup;
  49. void give_node_reference(Node);
  50. void give_symbol_reference(Symbol);
  51. void zpnodrefa(char *, Node);
  52. void zpset(Set);
  53. void zpsig(Symbol);
  54. void zpsigt();
  55. void zptup(Tuple);
  56. void zpsetsym(Set);
  57. void zpsym(Symbol);
  58. void zpsymrefa(char *, Symbol);
  59. void zpsymref(Symbol);
  60. void zpnodref(Node);
  61. int analyze(char *, explored, int *, int *);
  62.  
  63. static int adrflag = 1; /* non zero to print address values */
  64. static int stack_ptr = 0;
  65. static explored stack[ 100 ];
  66. static void push(explored);
  67. static explored pop();
  68. static void display_symbol(Symbol);
  69. static void zpcon1(Const);
  70. static void zprat1(Rational);
  71.  
  72.  
  73. /*
  74.  * The purpose of this program is to provide the one who is not familiar
  75.  * with the structure of the AST with a tool which permits him to travel
  76.  * from one node to his eventual father or son (we assume that the
  77.  * beginning of the exploration will take place at the root of the AST .)
  78.  * and focus on the nodes he wants to examine more precisely in a readable
  79.  * way . 
  80.  */
  81.  
  82.  
  83. static void push (explored site)                /*;push*/
  84. {
  85.     stack [ stack_ptr++ ] = site;
  86. }
  87.  
  88. static explored pop ()                    /*;pop*/
  89. {
  90.     return (stack [ --stack_ptr ]);
  91. }
  92.  
  93. static void display_symbol(Symbol symbol_explored)        /*;display_symbol*/
  94. {
  95.     short nature;
  96.  
  97.     system ("clear");
  98.  
  99.     if (symbol_explored == (Symbol)0)
  100.         printf ("(Symbol)0\n");
  101.     else {
  102.         printf("NATURE %s        %d \n\n",
  103.           nature_str (NATURE (symbol_explored)), symbol_explored);
  104.         printf("TYPE_OF %s   %d\n",
  105.           nature_str(NATURE(TYPE_OF(symbol_explored))),
  106.           TYPE_OF(symbol_explored));
  107.         printf("ALIAS   %s   %d\n",
  108.           nature_str(NATURE(ALIAS(symbol_explored))), ALIAS(symbol_explored));
  109.         printf("SIGNATURE :\n");
  110.     
  111.         if (SIGNATURE (symbol_explored) != ((Tuple)0))
  112.             zptup(SIGNATURE (symbol_explored));
  113.         else
  114.             printf("empty_tuple\n");
  115.  
  116.         if (SCOPE_OF(symbol_explored))
  117.             printf("SCOPE_OF %s   %d\n",
  118.               nature_str(NATURE(SCOPE_OF(symbol_explored))),
  119.               SCOPE_OF(symbol_explored));
  120.         else
  121.             printf("No scope.\n");
  122.  
  123.         printf("OVERLOADS :\n");
  124.         if (OVERLOADS (symbol_explored) != ((Tuple)0)) {
  125.             nature = NATURE(symbol_explored);
  126.             if (nature == na_enum)
  127.                 printf(" literal map %d\n", OVERLOADS(symbol_explored));
  128.             else if (nature == na_package || nature == na_package_spec
  129.               || nature == na_generic_package_spec
  130.               || nature == na_generic_package || nature == na_task_type
  131.               || nature == na_task_obj)
  132.                 printf(" private declarations %d\n",
  133.                     OVERLOADS(symbol_explored));
  134.             else 
  135.                 display_symbol_list  (OVERLOADS (symbol_explored), 1);
  136.         }
  137.         else
  138.             printf ("empty_set\n");
  139.         printf("DECLARED %d\n", DECLARED (symbol_explored));
  140.         if (ORIG_NAME (symbol_explored) != (char *)0)
  141.             printf("ORIG_NAME %s\n", ORIG_NAME (symbol_explored));
  142.         printf("SEQ %d\n", S_SEQ (symbol_explored));
  143.         printf("UNIT %d\n", S_UNIT (symbol_explored));
  144.         printf("TYPE_ATTR %d\n", TYPE_ATTR (symbol_explored));
  145.         if (MISC (symbol_explored) != (char *)0)
  146.             printf("MISC %s\n", MISC (symbol_explored));
  147.         printf("TYPE_KIND %d\n", TYPE_KIND (symbol_explored));
  148.         printf("TYPE_SIZE %d\n", TYPE_SIZE (symbol_explored));
  149.  
  150.         if (INIT_PROC(symbol_explored))
  151.             printf("INIT_PROC %s   %d\n",
  152.               nature_str(NATURE(INIT_PROC(symbol_explored))),
  153.               INIT_PROC(symbol_explored));
  154.         else printf("INIT_PROC = 0\n");
  155.  
  156.         printf("ASSOCIATED_SYMBOLS :\n");
  157.         if (ASSOCIATED_SYMBOLS (symbol_explored) != ((Tuple)0))
  158.             display_symbol_list (ASSOCIATED_SYMBOLS (symbol_explored), 1);
  159.         else
  160.             printf ("empty_tuple\n");
  161.         printf("SEGMENT %d\n", S_SEGMENT (symbol_explored));
  162.         printf("OFFSET %d\n", S_OFFSET (symbol_explored));
  163.         printf("\n");
  164.     }
  165. }
  166.  
  167. void display_node(Node node_explored, int list_begin)    /*;display_node*/
  168. {
  169.     int kind_explored;
  170.  
  171.     system ("clear");
  172.  
  173.     if (node_explored == (Node)0)
  174.         printf ("(Node)0\n");
  175.     else {
  176.         kind_explored = N_KIND (node_explored);
  177.  
  178.         printf ("kind -> %s  ", kind_str (kind_explored));
  179.         printf ("unit -> %d  ", N_UNIT (node_explored));
  180.         printf ("side -> %d  ", N_SIDE (node_explored));
  181.         printf ("overloaded -> %d  ", N_OVERLOADED (node_explored));
  182.         printf ("sequence -> %d ", N_SEQ (node_explored));
  183.         printf ("\n");
  184.         printf ("%d", kind_explored);
  185.  
  186.         printf ("\n");
  187.         printf ("\n");
  188.  
  189.         /*****************/
  190.         /* nu1 component */
  191.         /*****************/
  192.         printf (" nu1 :  ");
  193.  
  194.         if (N_AST1_DEFINED (kind_explored)) {
  195.             if (N_AST1(node_explored) != (Node)0)
  196.                 printf ("AST1 %s \n", kind_str(N_KIND(N_AST1(node_explored))));
  197.             else
  198.                 printf ("AST1 (Node)0 \n");
  199.         }
  200.         else 
  201.             printf ("SPAN %d %d \n", N_SPAN0 (node_explored),
  202.               N_SPAN1 (node_explored));
  203.  
  204.         printf ("\n");
  205.  
  206.         /*****************/
  207.         /* nu2 component */
  208.         /*****************/
  209.         printf (" nu2 :  ");
  210.  
  211.         if (N_AST2_DEFINED (kind_explored)) {
  212.             if (N_AST2(node_explored) != (Node)0)
  213.                 printf ("AST2 %s \n",
  214.                     kind_str(N_KIND(N_AST2(node_explored))));
  215.             else
  216.                 printf ("AST2 (Node)0 \n");
  217.         }
  218.         else if (N_LIST_DEFINED (kind_explored)) {
  219.             printf ("LIST ");
  220.             if (N_LIST (node_explored) != ((Tuple)0))
  221.                 display_node_list (N_LIST (node_explored), list_begin);
  222.             else 
  223.                 printf ("empty_tuple\n");
  224.         }
  225.         else { /* (N_VAL_DEFINED (kind_explored) */
  226.             display_value (node_explored);
  227.             printf ("\n");
  228.         }
  229.  
  230.         printf ("\n");
  231.  
  232.         /*****************/
  233.         /* nu3 component */
  234.         /*****************/
  235.         printf (" nu3 :  ");
  236.  
  237.         if (N_AST3_DEFINED (kind_explored)) {
  238.             if (N_AST3(node_explored) != (Node)0)
  239.                 printf ("AST3 %s \n", kind_str(N_KIND(N_AST3(node_explored))));
  240.             else
  241.                 printf ("AST3 (Node)0 \n");
  242.         }
  243.         else if (N_UNQ_DEFINED (kind_explored))
  244.             printf ("Symbol unq --> %s \n",
  245.               nature_str(NATURE(N_UNQ(node_explored))));
  246.         else {
  247.             printf ("N_NAMES ");
  248.             if (N_NAMES (node_explored) != ((Set)0))
  249.                 display_node_list((Tuple)N_NAMES(node_explored), list_begin);
  250.             else 
  251.                 printf ("empty_set\n");
  252.         }
  253.  
  254.         printf ("\n");
  255.  
  256.         /*****************/
  257.         /* nu4 component */
  258.         /*****************/
  259.         printf (" nu4 :  ");
  260.  
  261.         if (N_AST4_DEFINED (kind_explored)) {
  262.             if (N_AST4(node_explored) != (Node)0)
  263.                 printf ("AST4 %s \n", kind_str(N_KIND(N_AST4(node_explored))));
  264.             else
  265.                 printf ("AST4 (Node)0 \n");
  266.         }
  267.         else if (N_TYPE_DEFINED (kind_explored))
  268.             printf ("Symbol type --> %s \n",
  269.               nature_str(NATURE(N_TYPE(node_explored))));
  270.         else {
  271.             printf ("N_PTYPES ");
  272.             if (N_PTYPES (node_explored) != ((Set)0))
  273.                 display_node_list((Tuple)N_PTYPES(node_explored), list_begin);
  274.             else 
  275.                 printf ("empty_set\n");
  276.         }
  277.         printf ("\n");
  278.     }
  279. }
  280.  
  281. void explorast (Node root)                    /*;explorast*/
  282. {
  283.     explored current;
  284.     int      next_step;
  285.     int      list_node;
  286.     int      list_low;
  287.     char     answer[10];
  288.  
  289.     current.genre = NODE_GENRE;
  290.     current.addr.n = root;
  291.     list_low = 1;
  292.  
  293.     do {
  294.         if (current.genre == NODE_GENRE)
  295.             display_node   (current.addr.n, list_low);
  296.         else 
  297.             display_symbol (current.addr.s);
  298.  
  299.         next_step = UNDEFINED_STEP;
  300.         list_node = 0;
  301.  
  302.         while (next_step == UNDEFINED_STEP) {
  303.             printf (" what shall be the next step  ?  ");
  304.             scanf ("%10s", answer);
  305.             next_step = analyze (answer, current, &list_node, &list_low);
  306.         }
  307.  
  308.         switch (next_step) {
  309.         case 0 :
  310.             current = pop ();
  311.             break;
  312.         case 11:
  313.             push (current);
  314.             current.genre  = NODE_GENRE;
  315.             current.addr.n = N_AST1 (current.addr.n);
  316.             break;
  317.         case 21:
  318.             push (current);
  319.             current.genre  = NODE_GENRE;
  320.             current.addr.n = N_AST2 (current.addr.n);
  321.             break;
  322.